/**
 * @Method Description
 * @Author: hao zheng@
 * @Description:In User Settings Edit
 * @LastEditors: Please set LastEditors
 * @param {}
 * @return 
 * @createTime: 2021-12-17 15:15:13
 */
export default {
	methods: {
		toHex(hexStr) {
			let hex1 = hexStr.substring(0, 1);
			let hex2 = hexStr.substring(1, 2);
			var num = this.getHex(hex1) * 16 + this.getHex(hex2);
			return num;
		},
		getHex(hexS) {
			let aStr = hexS.toLowerCase();
			let num = 0;
			switch (aStr) {
				case "a":
					num = 10;
					break;
				case "b":
					num = 11;
					break;
				case "c":
					num = 12;
					break;
				case "d":
					num = 13;
					break;
				case "e":
					num = 14;
					break;
				case "f":
					num = 15;
					break;
				default:
					num = Number.parseInt(aStr);
			}
			return num;
		},
		toHexStr(uint8Data) {
			let str = "";
			let highByte = Math.floor(uint8Data / 16);
			switch (highByte) {
				case 10:
					str += "A";
					break;
				case 11:
					str += "B";
					break;
				case 12:
					str += "C";
					break;
				case 13:
					str += "D";
					break;
				case 14:
					str += "E";
					break;
				case 15:
					str += "F";
					break;
				default:
					str += highByte;
			}
			let lowByte = uint8Data % 16;
			switch (lowByte) {
				case 10:
					str += "A";
					break;
				case 11:
					str += "B";
					break;
				case 12:
					str += "C";
					break;
				case 13:
					str += "D";
					break;
				case 14:
					str += "E";
					break;
				case 15:
					str += "F";
					break;
				default:
					str += lowByte;
			}
			return str;
		},
		toHexStrs(byteDatas,type="list") {
			let byteStr = "";
			for (var i = 0; i < byteDatas.length; i++) {
				if(type=="list"){
					if (i > 1 && i != byteDatas.length - 1) {
						let byteData = byteDatas[i];
						byteStr = byteStr + " " + this.toHexStr(byteData);
					}
				}else{
					let byteData = byteDatas[i];
					byteStr = byteStr + " " + this.toHexStr(byteData);
				}
				
			}
			return byteStr.trim();
		}
		
	}
}
